How to copy the value of attributes between modules

Hello, 

I tried to script a code, which copies the value of "Variant_GSP" from customer to L2, using a configuration file. I created a button for verifying if the modules with outlinks has the attribute, and a button "copy value".  The script verifies if  the target object has or has not the attribute "Variant_GSP", but in the output, some attributes appeared in both lists. I can't figure out the error.  There's an if, but it seems that it enters both branches.

This is the code: 

    

 

void Verify(DBE calledfrom)
{
    Link outlinkRef
    AttrDef ad
    Link l
    Module mod = null
    m = current Module
    Object o 
    for o in m do {
    for outlinkRef in o ->" patht"     do{                
                string strModName = fullName target (outlinkRef)
                if (! open module strModName)     // opens the target module 
                    {mod = read (strModName, false)}
                bool boolOpend = open module strModName
                Object tgObj = target outlinkRef  // finds the target object                                                           
                                                        
                if((tgObj."_ObjectType""" == "")&& isMember(tgObj."   project ") )
                            {    
                            int found=0
                        for ad in  mod do {        
                            if (ad.name""== "Variant_GSP"  )
                                    {            found=1
                                                print "YES Object   " o."Absolute Number"""  "link to  "  tgObj."_ObjectType""" "\n"
                                                attr_found++}
                            if(found==0)
                             {    print  "No attribute in: " strModName" object  " o."Absolute Number""" "\n"}
                                
                            if(!boolOpend)
                                {close(mod)        }        
                        }    
                    
            }
   

void copyAttributeValue(DBE calledfrom)
{    Link outlinkRef
    Link l
    AttrDef ad
    Module mod = null
    m = current Module
    Object o 
    if(null m) {
        print "no module loaded"
        return
    }
    for o in m do {
    for outlinkRef in o ->"path"    do{                       
                string strModName = fullName target (outlinkRef)
                if (! open module strModName)     // opens the target module 
                mod = read (strModName, false)
                Object tgObj = target outlinkRef  // finds the target object                                                            
                        bool boolOpend = open module strModName                                
                if((tgObj."_ObjectType""" == " ")&& isMember(tgObj."_", "") )
                            {                    print " Object   " o."Absolute Number"""  "link to  "  tgObj."_ObjectType""" "\n"
                                                o."Variant_GSP" += tgObj."Variant_GSP"""    // adds the new value to the list
                                                        if(isMember(o."Variant_GSP","TBD")){
                                                            o."Variant_GSP" -= "TBD"""     }  //removes TBD from the list
                                                AttrChanged++
                                                print "Attr Changed number:  " AttrChanged""   "\n"
                                                                        }
                                            }                                                
 

 

 


Anamaria/ System Requirement - Mon Sep 19 07:16:30 EDT 2016

Re: How to copy the value of some attributes from customer to L2
Costas..Aravidis - Tue Sep 20 01:52:28 EDT 2016

I guess the code gives you an error.

 

This 

    o."Variant_GSP" += tgObj."Variant_GSP"""    // adds the new value to the list
        if(isMember(o."Variant_GSP","TBD")){
            o."Variant_GSP" -= "TBD"""     }  //removes TBD from the list

does not work in DXL. You cannot add or remove values from an attribute that is enumerated like that. You need to construct the whole string and assign it to the attribute i.e.

 

string s = "Value1\nValue2\nValue4"
o."Variant_GSP" = s

 

Providing that Value1 is before Value2 before Value3 before Value4 etc.

If you want to remove a value then you need to construct the string without it and the correct order.

This is the easiest way.

Re: How to copy the value of some attributes from customer to L2
Anamaria/ System Requirement - Thu Sep 22 02:42:11 EDT 2016

Costas..Aravidis - Tue Sep 20 01:52:28 EDT 2016

I guess the code gives you an error.

 

This 

    o."Variant_GSP" += tgObj."Variant_GSP"""    // adds the new value to the list
        if(isMember(o."Variant_GSP","TBD")){
            o."Variant_GSP" -= "TBD"""     }  //removes TBD from the list

does not work in DXL. You cannot add or remove values from an attribute that is enumerated like that. You need to construct the whole string and assign it to the attribute i.e.

 

string s = "Value1\nValue2\nValue4"
o."Variant_GSP" = s

 

Providing that Value1 is before Value2 before Value3 before Value4 etc.

If you want to remove a value then you need to construct the string without it and the correct order.

This is the easiest way.

Thank you, it helped. The code runs, but the error in the output is that it finds, for exemple:

 

No attribute in target object X

Attribute in target object X.

I mean, first it can find the attribute, then it finds the same attribute.